package com.zhiyou.aifeng.smart_machine

import android.os.Bundle
import com.zhiyou.aifeng.common.base.oneClick
import com.zhiyou.aifeng.common.helper.get
import com.zhiyou.aifeng.common.helper.getString
import com.zhiyou.aifeng.common.helper.trimString
import com.zhiyou.aifeng.common_ui.base.BaseActivity
import com.zhiyou.aifeng.common_ui.model.BaseUrl
import com.zhiyou.aifeng.viewmodel.SettingViewModel
import kotlinx.android.synthetic.main.activity_feedback.*
import org.jetbrains.anko.toast

class FeedbackActivity : BaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_feedback)
        initTitle("意见反馈", divider = false)
    }

    override fun getViewModel() = get<SettingViewModel>()

    override fun initTitle(title: String, name: String, divider: Boolean) {
        super.initTitle(title, name, divider)
        feed_submit.oneClick {
            if (feed_input.text.isBlank()) {
                toast("请输入要反馈的内容")
                return@oneClick
            }

            getViewModel().request(
                requestUrl = BaseUrl.feedback,
                params = *arrayOf(
                    "uid" to getString("userId"),
                    "content" to feed_input.trimString(),
                    "type" to 2
                ),
                onResult = {
                    toast("反馈信息提交成功！")
                    finishView()
                }
            )
        }
    }

}